#include "OptionMenuLayer.h"

OptionMenuLayer::OptionMenuLayer()
: pGameLayerManager(NULL)
{
}

OptionMenuLayer::~OptionMenuLayer()
{
}

OptionMenuLayer * OptionMenuLayer::create()
{
  OptionMenuLayer * pLayer = new OptionMenuLayer();
  if (pLayer && pLayer->init())
  {
    pLayer->autorelease();
    return pLayer;
  }
  else
  {
    CC_SAFE_DELETE(pLayer);
    return NULL;
  }
}

bool OptionMenuLayer::init()
{
  do
  {
    CC_BREAK_IF(!CCLayer::init());

    CCLabelTTF *pResumeLabel = CCLabelTTF::create("RESUME", "Arial", 40);
    CC_BREAK_IF(!pResumeLabel);
    CCMenuItemLabel * pResumeItemLabel = CCMenuItemLabel::create(pResumeLabel, this, menu_selector(OptionMenuLayer::onResume));
    CC_BREAK_IF(!pResumeItemLabel);
    pResumeItemLabel->setPositionY(50);

    CCLabelTTF *pExitLabel = CCLabelTTF::create("EXIT", "Arial", 40);
    CC_BREAK_IF(!pExitLabel);
    CCMenuItemLabel * pExitItemLabel = CCMenuItemLabel::create(pExitLabel, this, menu_selector(OptionMenuLayer::onExit));
    CC_BREAK_IF(!pExitItemLabel);
    pExitItemLabel->setPositionY(-50);

    CCMenu * pMenu = CCMenu::create(pResumeItemLabel, pExitItemLabel,  NULL);
    CC_BREAK_IF(!pMenu);
    addChild(pMenu);
    return  true;
  }
  while(0);
  return false;
}

void OptionMenuLayer::onResume(CCObject * pObj)
{
  pGameLayerManager->resumeGame();
}

void OptionMenuLayer::onExit(CCObject * pObj)
{
  pGameLayerManager->exitGame();
}

void OptionMenuLayer::setGameLayerManager(GameLayerManager * pGameLayerManager)
{
  this->pGameLayerManager = pGameLayerManager;
}
